<?php
define('FPDF_FONTPATH','font/');
require_once('fpdf.php');
require_once('gisp_admincon.php');
require_once('qrcode.class.php');
require_once("Connections/coneccionRatania.php");
require_once("Connections/funciones_pg.php");
//include_once('rotation.php');



	
	
class PDF extends FPDF{

var $angle=0;
var $javascript;
var $n_js;

	function IncludeJS($script) {
		$this->javascript=$script;
	}

	function _putjavascript() {
		$this->_newobj();
		$this->n_js=$this->n;
		$this->_out('<<');
		$this->_out('/Names [(EmbeddedJS) '.($this->n+1).' 0 R]');
		$this->_out('>>');
		$this->_out('endobj');
		$this->_newobj();
		$this->_out('<<');
		$this->_out('/S /JavaScript');
		$this->_out('/JS '.$this->_textstring($this->javascript));
		$this->_out('>>');
		$this->_out('endobj');
	}


function AutoPrint($dialog=false)
{
	//Open the print dialog or start printing immediately on the standard printer
	$param=($dialog ? 'true' : 'false');
	$script="print($param);";
	$this->IncludeJS($script);
}

function AutoPrintToPrinter($server, $printer, $dialog=false)
{
	//Print on a shared printer (requires at least Acrobat 6)
	$script = "var pp = getPrintParams();";
	if($dialog)
		$script .= "pp.interactive = pp.constants.interactionLevel.full;";
	else
		$script .= "pp.interactive = pp.constants.interactionLevel.automatic;";
	$script .= "pp.printerName = '\\\\\\\\".$server."\\\\".$printer."';";
	$script .= "print(pp);";
	$this->IncludeJS($script);
}


	function _putresources() {
		parent::_putresources();
		if (!empty($this->javascript)) {
			$this->_putjavascript();
		}
	}

	function _putcatalog() {
		parent::_putcatalog();
		if (!empty($this->javascript)) {
			$this->_out('/Names <</JavaScript '.($this->n_js).' 0 R>>');
		}
	}
	

function Rotate($angle,$x=-1,$y=-1)
{
	if($x==-1)
		$x=$this->x;
	if($y==-1)
		$y=$this->y;
	if($this->angle!=0)
		$this->_out('Q');
	$this->angle=$angle;
	if($angle!=0)
	{
		$angle*=M_PI/180;
		$c=cos($angle);
		$s=sin($angle);
		$cx=$x*$this->k;
		$cy=($this->h-$y)*$this->k;
		$this->_out(sprintf('q %.5F %.5F %.5F %.5F %.2F %.2F cm 1 0 0 1 %.2F %.2F cm',$c,$s,-$s,$c,$cx,$cy,-$cx,-$cy));
	}
}

function _endpage()
{
	if($this->angle!=0)
	{
		$this->angle=0;
		$this->_out('Q');
	}
	parent::_endpage();
}

function RotatedText($x,$y,$txt,$angle)
{
    //Text rotated around its origin
    $this->Rotate($angle,$x,$y);
    $this->Text($x,$y,$txt);
    $this->Rotate(0);
}

function RoundedRect($x, $y, $w, $h, $r, $style = '')
    {
        $k = $this->k;
        $hp = $this->h;
        if($style=='F')
            $op='f';
        elseif($style=='FD' || $style=='DF')
            $op='B';
        else
            $op='S';
        $MyArc = 4/3 * (sqrt(2) - 1);
        $this->_out(sprintf('%.2F %.2F m',($x+$r)*$k,($hp-$y)*$k ));
        $xc = $x+$w-$r ;
        $yc = $y+$r;
        $this->_out(sprintf('%.2F %.2F l', $xc*$k,($hp-$y)*$k ));

        $this->_Arc($xc + $r*$MyArc, $yc - $r, $xc + $r, $yc - $r*$MyArc, $xc + $r, $yc);
        $xc = $x+$w-$r ;
        $yc = $y+$h-$r;
        $this->_out(sprintf('%.2F %.2F l',($x+$w)*$k,($hp-$yc)*$k));
        $this->_Arc($xc + $r, $yc + $r*$MyArc, $xc + $r*$MyArc, $yc + $r, $xc, $yc + $r);
        $xc = $x+$r ;
        $yc = $y+$h-$r;
        $this->_out(sprintf('%.2F %.2F l',$xc*$k,($hp-($y+$h))*$k));
        $this->_Arc($xc - $r*$MyArc, $yc + $r, $xc - $r, $yc + $r*$MyArc, $xc - $r, $yc);
        $xc = $x+$r ;
        $yc = $y+$r;
        $this->_out(sprintf('%.2F %.2F l',($x)*$k,($hp-$yc)*$k ));
        $this->_Arc($xc - $r, $yc - $r*$MyArc, $xc - $r*$MyArc, $yc - $r, $xc, $yc - $r);
        $this->_out($op);
    }

    function _Arc($x1, $y1, $x2, $y2, $x3, $y3)
    {
        $h = $this->h;
        $this->_out(sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c ', $x1*$this->k, ($h-$y1)*$this->k,
            $x2*$this->k, ($h-$y2)*$this->k, $x3*$this->k, ($h-$y3)*$this->k));
    }
	
	function Header(){
		//datos SQL
		global $login;
		global $centro_costo;
		global $nom_oficina;
		global $cod_actproy;
		global $des_actproy;
		global $cod_nemonico;
		global $des_nemonico;
		global $title;
		global $nro_nec;
		global $ano_eje;
		global $fch_nec;
		global $tipo_bien;
		global $reqs_anuales;			
		global $topIni;
		global $marIni;
		global $wcel;
		global $empresaM;
		global $distrito;
		global $departamento;
		global $provincia;
		global $logoCabIzq;
		global $logoSupP1;
		global $logoSupP2;
		global $logoSupP3;
		global $logoSupP4;
		global $marcaAguaP1;
		global $marcaAguaL1;
		global $marcaAguaL2;
		global $marcaAguaL3;
		global $marcaAguaL4;global $marcaAguaP2;
		global $marcaAguaP3;
		global $marcaAguaP4;
		global $marcaDeAgua;
		global $repositorioFirmas;
		global $RUC;
		global $numero_recibo;
		global $codigoContrib;
		global $nombreContrib;
		global $nroDoc;
		global $direccionContrib;
		global $cajero;
		global $fechaEmision;
		global $fechaImpresion;
		global $fechaProyectado1;
                global $fechaIni;
                global $fechaFin;
		global $err;
		global $fechaRecargos;
		global $usuario;
		global $colCab;
		global $colSubCab;
                global $subTipoReporte;
                global $tipoReporte;
                global $cidusuario;
 global $nombreusuario;
 global $vobserv; 
 global $cidUser;
 global $usuarioDDJJ;
 
 
 
		
		$tamInfoCuadro = -16;
                $posInfoCuadro = 26;
                $tamInfoCuadro2 = -9;
                $posInfoCuadro2 = 9;
                $tamcabecera=30;
		
		$lw = $marIni;
		$ln = $topIni;
		$ls = 3;
		$lh = 0;
		//MArca de Agua
		$this->Image('../img/marca/escudomarcaagua4.png',$marcaAguaL1-20,$marcaAguaL2,$marcaAguaL3+50,$marcaAguaL4+50,'PNG');
		
		//Logo
		$this->SetFont('arial','B',9);
		//$this->SetFillColor(206,232,212); //verde agua
		$this->SetFillColor(188,217,190); //verde agua
		$this->SetXY($lw-10,$lh);
		$this->Cell(220,8,"",0,1,'L',true);
		$this->SetFillColor(243);
		$this->SetFont('arial','B',9);
		$this->SetXY($lw-10,$lh);
		$this->MultiCell(50,8,'Calle 9 de Junio Nro 100',1,'C');
		$this->SetXY($lw+40,$lh);
		$this->MultiCell(50,8,'Puente Piedra - Lima - Peru',1,'C');
		$this->SetXY($lw+90,$lh);
		$this->MultiCell(50,8,'www.munipuentepiedra.gob.pe',1,'C');
		$this->SetXY($lw+140,$lh);
		$this->MultiCell(60,8,'Telefono 219 6200 - 219 6201',1,'C');
		//$this->RoundedRect(-10, 0, 220, 8, 1,'S');
		$this->Image('../img/marca/munipuentepiedra.png',$lw,$ln,62,18,'PNG');
		
		//$this->SetFillColor(145,185,154); //verde agua
		$this->SetFillColor(255);
		$lh = $lh+9;
		$this->SetXY($lw+70,$lh);
		$this->Cell(160,12,"",0,1,'L',true);
		$this->SetFont('arial','B',14);
		$this->SetXY($lw+60,$lh);
		$this->MultiCell(140,5,'SUB GERENCIA DE REGISTRO y FISCALIZACION TRIBUTARIA',0,'C');
		
		
		//definimos  ancho y color de rectangulo
		$lh = $lh+20;
		$this->SetLineWidth(0.3);
		$this->SetFillColor(255);
		$this->RoundedRect($lw-5, $lh, 110+$tamcabecera, 27, 1, '');
		$this->SetFont('arial','B',12);
		$this->SetXY($lw+10,$lh+2);
		$this->MultiCell(120,5,$tipoReporte,0,'J');
		$this->SetFont('arial','B',12);
		$this->SetXY($lw+10,$lh+12);
		$this->MultiCell(120,5,$subTipoReporte,0,'J');
                $this->SetFont('arial','B',12);
		$this->SetXY($lw+10,$lh+18);
		$this->MultiCell(120,5,'',0,'J');
		
		//$qrcode = new QRcode(utf8_encode('Hola'), $err);
		//$qrcode->disableBorder();
		
		//aqui va el codigo de barras
		//$qrcode->displayHTML();
		//$this->SetXY($lw+10,$lh+12);
		//$qrcode->displayPNG(50);
		//$this->Image(,$lw,$ln,62,18,'PNG');
		
		//$this->SetXY($lw,$lh + 17 );
		$this->Image('../img/marca/barraBoucher_2dat.gif',$lw-3,$lh+12,13,13,'GIF','');
		
                //$posInfoCuadro
                //+$tamInfoCuadro
                $ls = 6;
		//$this->RoundedRect($lw+110, $lh-$ls, 85, 27, 1, '');
                
		
		
		$this->SetFont('arial','',8);
		$this->SetXY($lw+110+$posInfoCuadro,$lh+8-$ls);
		$this->Cell(42+$tamInfoCuadro,8,"",1,1,'L',true);
		$this->SetXY($lw+112+$posInfoCuadro,$lh+9-$ls);
		$this->MultiCell(40+$tamInfoCuadro,5,'Desde',0,'J');
		$this->SetXY($lw+152+$posInfoCuadro2,$lh+8-$ls);
		$this->Cell(43+$tamInfoCuadro2,8,"",1,1,'L',true);
		$this->SetXY($lw+152+$posInfoCuadro2,$lh+9-$ls);
		$this->SetFont('f25bankprinter','',10);
		$this->MultiCell(43+$tamInfoCuadro2,5,$fechaIni,0,'R');
                
                $this->SetFont('arial','',8);
		$this->SetXY($lw+110+$posInfoCuadro,$lh+14-$ls);
		$this->Cell(42+$tamInfoCuadro,8,"",1,1,'L',true);
		$this->SetXY($lw+112+$posInfoCuadro,$lh+15-$ls);
		$this->MultiCell(40+$tamInfoCuadro,5,'Hasta',0,'J');
		$this->SetXY($lw+152+$posInfoCuadro2,$lh+14-$ls);
		$this->Cell(43+$tamInfoCuadro2,8,"",1,1,'L',true);
		$this->SetXY($lw+152+$posInfoCuadro2,$lh+15-$ls);
		$this->SetFont('f25bankprinter','',10);
		$this->MultiCell(43+$tamInfoCuadro2,5,$fechaFin,0,'R');
		
		
		$this->SetFont('arial','',8);
		$this->SetXY($lw+110+$posInfoCuadro,$lh+20-$ls);
		$this->Cell(42+$tamInfoCuadro,6,"",1,1,'L',true);
		$this->SetXY($lw+112+$posInfoCuadro,$lh+21-$ls);
		$this->MultiCell(40+$tamInfoCuadro,4,'Usuario Imprime',0,'J');
		$this->SetXY($lw+152+$posInfoCuadro2,$lh+20-$ls);
		$this->Cell(43+$tamInfoCuadro2,6,"",1,1,'L',true);
		$this->SetXY($lw+152+$posInfoCuadro2,$lh+21-$ls);
		$this->SetFont('f25bankprinter','',10);
		$this->MultiCell(43+$tamInfoCuadro2,4,$usuario,0,'R');
		
		$this->SetFont('arial','',8);
		$this->SetXY($lw+110+$posInfoCuadro,$lh+26-$ls);
		$this->Cell(42+$tamInfoCuadro,7,"",1,1,'L',true);
		$this->SetXY($lw+112+$posInfoCuadro,$lh+27-$ls);
		$this->MultiCell(40+$tamInfoCuadro,4,'Fecha Impresion',0,'J');
		$this->SetXY($lw+152+$posInfoCuadro2,$lh+26-$ls);
		$this->Cell(43+$tamInfoCuadro2,7,"",1,1,'L',true);
		$this->SetXY($lw+152+$posInfoCuadro2,$lh+27-$ls);
		$this->SetFont('f25bankprinter','',7);
		$this->MultiCell(43+$tamInfoCuadro2,4,$fechaImpresion,0,'R');
		
                $lh = $lh +35;
		
               


		$ls=-5;
                $this->SetFillColor(188,217,190); //verde agua
		$this->SetFont('arial','B',8);
		$this->SetXY($lw+$ls,$lh);
		$this->Cell($colSubCab[0][0]*2,5,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh+1);
		$this->MultiCell($colSubCab[0][0]*2,3,'USUARIO',0,'C');
		
                $ls = $colSubCab[0][0]*2-5;
                $this->SetFillColor(255,255,255); //Blanco
                $this->SetXY($lw+$ls,$lh);
		$this->Cell($colSubCab[0][0]*2,5,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh+1);
		$this->MultiCell($colSubCab[0][0]*2,3,$usuarioDDJJ,0,'C');
		
		$ls = $colSubCab[0][0]*2+$colSubCab[0][0]*2-5;
                 $this->SetFillColor(188,217,190); //verde agua
		$this->SetFont('arial','B',8);
		$this->SetXY($lw+$ls,$lh);
		$this->Cell($colCab[3]*2,5,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh+1);
		$this->MultiCell($colCab[3]*2,3,  'Nombre y Apellidos',0,'C');
		
		$ls = $colSubCab[0][0]*2+$colSubCab[0][0]*2+$colCab[3]*2-5;
                $this->SetFillColor(255,255,255); //Blanco
		$this->SetFont('arial','B',8);
		$this->SetXY($lw+$ls,$lh);
		$this->Cell($colCab[5],5,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh+1);
		$this->MultiCell($colCab[5],3, $cidusuario." - ".$nombreusuario,0,'C');	
                
        $lh = $lh +5;
		
		$ls=-5;
        $this->SetFillColor(188,217,190); //verde agua
		$this->SetFont('arial','B',8);
		$this->SetXY($lw+$ls,$lh);
		$this->Cell($colSubCab[0][0]*2,5,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh+1);
		$this->MultiCell($colSubCab[0][0]*2,3,'Nro DDJJ',0,'C');
		
		$ls = $colSubCab[0][0]*2-5;
		$this->SetFillColor(188,217,190); //verde agua
		$this->SetFont('arial','B',8);
		$this->SetXY($lw+$ls,$lh);
		$this->Cell($colSubCab[0][0]*2,5,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh);
		$this->Cell($colSubCab[0][0]*2,5,"Fecha DDJJ",1,1,'L',true);
		
		
		$ls = $colSubCab[0][0]*4-5;
		$this->SetFillColor(188,217,190); //verde agua
		$this->SetFont('arial','B',8);
		$this->SetXY($lw+$ls,$lh);
		$this->Cell($colSubCab[0][0]*4,5,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh+1);
		$this->MultiCell($colSubCab[0][0]*4,3,"Motivo",0,'C');
		
		$ls = $colSubCab[0][0]*8-5;
        $this->SetFillColor(188,217,190); //verde agua
		$this->SetFont('arial','B',8);
		$this->SetXY($lw+$ls,$lh);
		$this->Cell($colSubCab[0][0]*2,5,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh);
		$this->Cell($colSubCab[0][0]*2,5,"Nro Contrib",1,1,'L',true);
		
		
		$ls = $colSubCab[0][0]*10-5;
		$this->SetFillColor(188,217,190); //verde agua
		$this->SetFont('arial','B',8);
		$this->SetXY($lw+$ls,$lh);
		$this->Cell($colSubCab[0][0]*10,5,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh+1);
		$this->MultiCell($colSubCab[0][0]*10,3,  'Apellidos y Nombres',0,'C');
		
		
		
                
		

		
	}
	
	function Footer(){
		global $marini;
		global $nro_nec;
		global $ano_eje;
		global $nombreGispAdmincon;
		//Posición: a 1,5 cm del final
		$this->SetXY($marini,-15);
		//Arial italic 8
		$this->SetFont('Arial','',10);
		//Número de página
		$this->Cell(79,5,'Municipalidad Distrital de Puente Piedra',0,0,'L',0);
		$this->SetFont('Arial','',8);
		$this->SetXY($marini,-10);
		$this->Cell(0,5,utf8_decode('Pagina N° ').$this->PageNo().' de {nb}',0,0,'R');
		$this->SetXY($marini,-10);
		$this->Cell(79,5,'GIT - Gestor Integrado Tributario',0,0,'L',0);
		
	}
	
	function WriteResumen($x,$h,$topmar, $corte){
		//datos SQL
		global $Coneccion;
		global $ano_eje;
		global $nro_nec;

		//datos DOC
		global $marini;
		global $topmar;
		global $repositorioFirmas;
                global $fechaFin;
                global $fechaIni;
                global $cajero2;
                global $cajero3;
                global $ConeccionRatania;
                global $cidUser;
                global $ccajero;
                global $usuarioCaja;
                
		

		
		if($h >= 210){
                    $corte = $this->CheckPageBreak(261);
			if($corte){
				$this->SetXY(15,$topmar + 5);
				//$this->Write(12,'corte 1');
			}/*
                          else{
				$this->SetXY(15,$h + 10);
				//$this->Write(10,'corte 0');
			}*/
		}else{
			$this->SetXY(15,$h + 5);
			//$this->Write(12,'corte 3');
		}

		$style = array('width' => 0.1, 'cap' => 'round', 'join' => 'round', 'dash' => '0', 'phase' => 10, 'color' => array(0,0,0));
		$this->Line(0, 0, 1, 0, $style);
		
        return $flag;
	}
	
	function CheckPageBreak($h){
		if($h >= 240){
			$this->AddPage();	
			return 1;
		}else{
			$this->SetY($h);
			return 0;
		}
		
	}
	
	
}


$usuario = $_GET['P_USERIMPR'];
$cajero =  $_GET['P_NROCAJA'];
$cidUser =  trim($_GET['P_CIDUSER']);
$p_usernm =  $_GET['P_USERNM'];
$cajero2 = $cajero;
$fechaIni=$_GET['P_FECHADESDE'];
$fechaFin=$_GET['P_FECHAHASTA'];
$subTipoReporte = 'DECLARACIONES JURADAS';
$tipoReporte = 'REPORTE DE CIERE DE DIA';

$pdf = new PDF('P','mm','A4');
$pdf->SetDisplayMode('fullpage');


if($cidUser=='' or !isset($cidUser) or $cidUser=='undefined'){
    $cidUser ='%';
}

$Rs_grabarCAB = new TSPResult($ConeccionRatania,"");
$Rs_grabarCAB->Poner_MSQL(" 
SELECT t1.idsigma,to_char(t1.dfecdoc,'dd/mm/YYYY') as fechadoc,t1.mperson as contrib,
(t3.vpatern||' '||t3.vmatern||' '||t3.vnombre) as nombrecontrib,
t1.vnrodoc,t1.cmotivo,
(SELECT t2.vdescri FROM public.mconten as t2
WHERE t2.idsigma=t1.cmotivo) as desmotivo,
t1.vusernm,(SELECT t2.usuario FROM seguridad.usuario as t2
WHERE t2.cidusuario=t1.vusernm) as usuario,
t1.vobserv ,
(SELECT (t6.vpatern||' '||t6.vmatern||' '||t6.vnombre) 
FROM public.mperson as t6,seguridad.usuario as t5
WHERE t6.idsigma=t5.cidpers
AND t5.cidusuario=t1.vusernm ) as nombreusuario FROM registro.mhresum as t1,
public.mperson as t3
WHERE t3.idsigma=t1.mperson
AND t1.dfecdoc>='".$fechaIni." 00:00:00' AND t1.dfecdoc<='".$fechaFin." 23:59:59'
/*AND t1.vusernm='".$cidUser."'*/
ORDER BY t1.vusernm,t1.idsigma DESC 

");
$Rs_grabarCAB->pg_Poner_Esquema("tesoreria");

$Rs_grabarCAB->executeMSQL();


//echo "<br><br>CONSULTA REQ UPDATE <br> ".$Rs_grabarCAB->Escribir_Consulta();

$NCAB = 0;
$numRowsCAB = $Rs_grabarCAB->pg_Num_Rows();
$rowCAB= $Rs_grabarCAB->pg_Get_Row();
$p_cperiod = $p_cperiod3;
//$NPeriodos=1;
//echo $numRowsCAB;


//$cajero='NDIESTRO';
//$usuario='NDIESTRO';
//$fechaEmision='12-12-2013 15:56';

//echo 'HOLA '.$fechaProyectado ;
//echo 'USUARIO '.$usuario ;


date_default_timezone_set('America/Lima');
$fechaImpresion="19/06/2014 17:45:59"; 
//$fechaImpresion=strftime('%d/%m/%Y %H:%M:%S'); 
$nroDoc='42215638';
//$fechaProyectado = '13/12/2013';
//$fechaRecargos = '13/12/2013';
if (!in_array($err, array('L', 'M', 'Q', 'H'))) $err = 'Q';

$colCab = array('61','105','51','25','220','110');
$colSubCab[0] = array('10','8','18');
$colSubCab[1] = array('18','20','25');
$colSubCab[2] = array('18','8','25');

$topIni = 10;
$marIni = 10; 
$topmar = 75;
//$lw=10;


//$pdf->AutoPrint();
//$pdf->AutoPrint();
$pdf->AliasNbPages();

$pdf->SetFont('Arial','B',16);


//$var1 = $pdf->GetY()+2;
//$var1 = $topmar+5;
//$pdf->SetXY($lw,$lh = $var1);
$lh = $topmar;
$rowCab= $Rs_grabarCAB->pg_Get_Row(); 
$cidusuario=$rowCab['vusernm'];
$nombreusuario=utf8_decode(trim($rowCab['nombreusuario']));
$usuarioDDJJ=$rowCab['usuario']; 
$pdf->AddPage();
$rowCab= $Rs_grabarCAB->pg_Get_Row(); 
$cidusuarioAnt = $rowCab['vusernm'];
while($NCAB < $numRowsCAB){

    


$RUC='20131366702';
$numero_recibo='860100100014';

$rowCab= $Rs_grabarCAB->pg_Get_Row(); 

$cidusuario=$rowCab['vusernm'];
$nombreusuario=utf8_decode(trim($rowCab['nombreusuario']));
$fechadoc=$rowCab['fechadoc'];
$contrib=$rowCab['contrib'];
$nombrecontrib=utf8_decode(trim($rowCab['nombrecontrib']));
$vnrodoc=$rowCab['vnrodoc']; 
$cmotivo=$rowCab['cmotivo']; 
$desmotivo=$rowCab['desmotivo']; 
$usuarioDDJJ=$rowCab['usuario']; 

$vobserv =trim($rowCab['vobserv']);
$vobserv = ereg_replace("<p>", "",$vobserv);
$vobserv = ereg_replace("</p>", "",$vobserv);
$vobserv = ereg_replace("[\n|\r|\n\r]", " ", $vobserv);
$vobserv = ereg_replace("<br>", " ", $vobserv);
$vobserv = ereg_replace("</br>", " ", $vobserv);
$vobserv = ereg_replace("&nbsp;", " ", $vobserv);
$vobserv=  utf8_decode($vobserv ) ; 




		

                $lw=$marIni;
				
				if($cidusuario<>$cidusuarioAnt){
				
				$cidusuarioAnt=$cidusuario;
				$ls=-5;
                $pdf->SetFillColor(188,217,190); //verde agua
				$pdf->SetFont('arial','B',8);
				$pdf->SetXY($lw+$ls,$lh);
				$pdf->Cell($colSubCab[0][0]*2,5,"",1,1,'L',true);
				$pdf->SetXY($lw+$ls,$lh+1);
				$pdf->MultiCell($colSubCab[0][0]*2,3,'USUARIO',0,'C');
				
						$ls = $colSubCab[0][0]*2-5;
						$pdf->SetFillColor(255,255,255); //Blanco
						$pdf->SetXY($lw+$ls,$lh);
				$pdf->Cell($colSubCab[0][0]*2,5,"",1,1,'L',true);
				$pdf->SetXY($lw+$ls,$lh+1);
				$pdf->MultiCell($colSubCab[0][0]*2,3,$usuarioDDJJ,0,'C');
				
				$ls = $colSubCab[0][0]*2+$colSubCab[0][0]*2-5;
						 $pdf->SetFillColor(188,217,190); //verde agua
				$pdf->SetFont('arial','B',8);
				$pdf->SetXY($lw+$ls,$lh);
				$pdf->Cell($colCab[3]*2,5,"",1,1,'L',true);
				$pdf->SetXY($lw+$ls,$lh+1);
				$pdf->MultiCell($colCab[3]*2,3,  'Nombre y Apellidos',0,'C');
				
				$ls = $colSubCab[0][0]*2+$colSubCab[0][0]*2+$colCab[3]*2-5;
						$pdf->SetFillColor(255,255,255); //Blanco
				$pdf->SetFont('arial','B',8);
				$pdf->SetXY($lw+$ls,$lh);
				$pdf->Cell($colCab[5],5,"",1,1,'L',true);
				$pdf->SetXY($lw+$ls,$lh+1);
				$pdf->MultiCell($colCab[5],3, $cidusuario." - ".$nombreusuario,0,'C');	
						
				$lh = $lh +5;
				
				$ls=-5;
				$pdf->SetFillColor(188,217,190); //verde agua
				$pdf->SetFont('arial','B',8);
				$pdf->SetXY($lw+$ls,$lh);
				$pdf->Cell($colSubCab[0][0]*2,5,"",1,1,'L',true);
				$pdf->SetXY($lw+$ls,$lh+1);
				$pdf->MultiCell($colSubCab[0][0]*2,3,'Nro DDJJ',0,'C');
				
				$ls = $colSubCab[0][0]*2-5;
				$pdf->SetFillColor(188,217,190); //verde agua
				$pdf->SetFont('arial','B',8);
				$pdf->SetXY($lw+$ls,$lh);
				$pdf->Cell($colSubCab[0][0]*2,5,"",1,1,'L',true);
				$pdf->SetXY($lw+$ls,$lh);
				$pdf->Cell($colSubCab[0][0]*2,5,"Fecha DDJJ",1,1,'L',true);
				
				
				$ls = $colSubCab[0][0]*4-5;
				$pdf->SetFillColor(188,217,190); //verde agua
				$pdf->SetFont('arial','B',8);
				$pdf->SetXY($lw+$ls,$lh);
				$pdf->Cell($colSubCab[0][0]*4,5,"",1,1,'L',true);
				$pdf->SetXY($lw+$ls,$lh+1);
				$pdf->MultiCell($colSubCab[0][0]*4,3,"Motivo",0,'C');
				
				$ls = $colSubCab[0][0]*8-5;
				$pdf->SetFillColor(188,217,190); //verde agua
				$pdf->SetFont('arial','B',8);
				$pdf->SetXY($lw+$ls,$lh);
				$pdf->Cell($colSubCab[0][0]*2,5,"",1,1,'L',true);
				$pdf->SetXY($lw+$ls,$lh);
				$pdf->Cell($colSubCab[0][0]*2,5,"Nro Contrib",1,1,'L',true);
				
				
				$ls = $colSubCab[0][0]*10-5;
				$pdf->SetFillColor(188,217,190); //verde agua
				$pdf->SetFont('arial','B',8);
				$pdf->SetXY($lw+$ls,$lh);
				$pdf->Cell($colSubCab[0][0]*10,5,"",1,1,'L',true);
				$pdf->SetXY($lw+$ls,$lh+1);
				$pdf->MultiCell($colSubCab[0][0]*10,3,  'Apellidos y Nombres',0,'C');
				
				$lh = $lh +5;
				
				}
				
                $lz += 0;
				$ls=-5;    
				$pdf->SetFont('arial','',7);
				$pdf->SetXY($lw+$ls,$lh);
				$pdf->Cell($colSubCab[0][0]*2,7,"",1,1,'L');
				$pdf->SetXY($lw+$ls,$lh+1);
				$pdf->MultiCell($colSubCab[0][0]*2,3,$vnrodoc,0,'L');
				
				$ls = $colSubCab[0][0]*2-5;
				$pdf->SetFont('arial','',7);
				$pdf->SetXY($lw+$ls,$lh);
				$pdf->Cell($colSubCab[0][0]*2,7,"",1,1,'L');
				$pdf->SetXY($lw+$ls,$lh+1);
				$pdf->MultiCell($colSubCab[0][0]*2,3,$fechadoc,0,'L');
				
				
				$ls = $colSubCab[0][0]*4-5;
				$pdf->SetFont('arial','',7);
				$pdf->SetXY($lw+$ls,$lh);
				$pdf->Cell($colSubCab[0][0]*4,7,"",1,1,'L');
				$pdf->SetXY($lw+$ls,$lh+1);
				$pdf->MultiCell($colSubCab[0][0]*4,3,$desmotivo,0,'J');
				
				$ls = $colSubCab[0][0]*8-5;
				$pdf->SetFont('arial','',7);
				$pdf->SetXY($lw+$ls,$lh);
				$pdf->Cell($colSubCab[0][0]*2,7,"",1,1,'L');
				$pdf->SetXY($lw+$ls,$lh+1);
				$pdf->MultiCell($colSubCab[0][0]*2,3,$contrib,0,'L');
				
				
				$ls = $colSubCab[0][0]*10-5;
				$pdf->SetXY($lw+$ls,$lh);
				$pdf->Cell($colSubCab[0][0]*10,7,"",1,1,'L');
				$pdf->SetFont('arial','',7);
				$pdf->SetXY($lw+$ls,$lh+1);
				$pdf->MultiCell($colSubCab[0][0]*10,3,$nombrecontrib,0,'J');
				
				$ls=-5; 
				$lh=$lh+7;
				$pdf->SetXY($lw+$ls,$lh);
				$pdf->Cell($colSubCab[0][0]*20,12,"",1,1,'L');
				$pdf->SetFont('arial','',7);
				$pdf->SetXY($lw+$ls,$lh+1);
				$pdf->MultiCell($colSubCab[0][0]*20,3,$vobserv,0,'J');



                $var1 = $pdf->GetY();
                if($corte = $pdf->CheckPageBreak($var1)) $lh = $topmar-12;	
                
               $lh += $lz+12;
               $lz =0;
                        
                
				$Rs_grabarCAB->pg_Move_Next();
				$NCAB++;
}                 
                 

$pdf->Output();


?>